import json
import os
import time

from camera.camera import Camera


def get_human_coordinates(img_path: str = None, task: str = None):
    human_response_path: str = "/home/knowin/codes/knowin-robot/txts/message_response.json"

    # clear the cache
    if os.path.exists(human_response_path):
        os.remove(human_response_path)

    while True:
        if not os.path.exists(human_response_path):
            print(
                f"{human_response_path} not found, please use vlms/human_pixel.py to choose pixels manually!", end="\r"
            )
            time.sleep(1)
        else:
            with open(human_response_path, "r") as f:
                message = json.load(f)
                os.remove(human_response_path)
                print(f"{human_response_path} is sent to the robot and removed!")
                return message
